<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>CFHibernate Test</title>
</head>

<body>

<cfset dsn = "cfhibernate">
<cfset userDAO = createObject("component", "cfhibernate.model.user.userDAO").init(dsn)>
<cfset userService = createObject("component", "cfhibernate.model.user.userService")>
<cfset userService.setUserDAO(userDAO)>

<cfset address = createObject("component", "cfhibernate.model.user.address.address").init()>
<cfset address.setAddress1("7909 Isleton Ave S")>
<cfset address.setAddress2("Apt 1")>
<cfset address.setCompany("KDub Web Design")>
<cfset address.setCity("Cottage Grove")>
<cfset address.setState("MN")>
<cfset address.setZip("55016")>

<cfset user = createObject("component", "cfhibernate.model.user.user").init()>
<cfset user.setFirstName("Kurt")>
<cfset user.setLastName("Wiersma")>
<cfset user.setMiddleName("Rustan")>
<cfset user.setEmail("kwiersma@mac.com")>
<cfset user.addAddress(address)>

<cfdump var="#user.getInstanceMemento()#" label="user">

<cfset user2 = userDAO.mapToHashMap(user)>

<cfoutput>
<cfloop list="#structKeyList(user2)#" index="field">
	#field#: #user2[field].getClass().getName()# | #user2[field]#<br />
	<cfif user2[field].getClass().getName() eq "java.util.HashSet">
		<cfset addresses = user2[field]>
		<cfset iterator = addresses.iterator()>
		<cfloop condition="#iterator.hasNext()#">
			<cfset element = iterator.next()>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#element.getClass().getName()# | #element.toString()#<br />
			<cfif element.getClass().getName() eq "java.util.HashMap">
				<cfloop list="#structKeyList(element)#" index="field2">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					#field2#: #element[field2].getClass().getName()# | #element[field2]#<br />
				</cfloop>
			</cfif>
		</cfloop>
	</cfif>
</cfloop>
</cfoutput>

<cfset sessionFactory = Application.hibernateConfig.buildSessionFactory()>
<cfset EntityMode = createObject("java", "org.hibernate.EntityMode")>
<cfset mySession = sessionFactory.openSession()>
<cfset userMetaData = sessionFactory.getClassMetaData("cfhibernate.model.user.user")>
<cfset addressMetaData = sessionFactory.getClassMetaData("cfhibernate.model.user.address.address")>

<cfoutput>
<p>email type = #userMetaData.getPropertyType("email").getName()#<br />
address.id type = #addressMetaData.getIdentifierType().getName()#
</p>
</cfoutput>

<cfset userService.saveUser(user)>

<!--- <cfset user = userService.getUser(40)> --->

<cfdump var="#user.getInstanceMemento()#" label="user">
	
</body>
</html>
